
include "media_center.thrift"

namespace go media_router

enum RespStatus {
    ERROR = -1
    EMPTY = 0
    OK = 1
}

enum Method {
    ADD = 0,
    GET,
    UPDATE,
    LIST,
    DELETE,
}
struct Response {
    1:string connID
    2:string paramID
    3:i32  method
    4:bool isOK
    5:i32 err_code
    6:string err_msg
}

struct page {
    1:i64 pagePre
    2:i64 pageNext
    3:string paramID
}

struct reqMedia{
    1:page page
    2:media_center.media media
}

struct reqMediaStream{
    1:page page
    2:media_center.stream stream
}


struct respMedia{
    1: Response Response
    2:list<media_center.media> MediaList
}

struct respMediaStream{
    1: Response Response
    2:list<media_center.stream> MediaStreamList
}


struct PlayRequest {
    1:string DeviceID //摄像头id
    2:string StreamID //流ID
    3:string UserCity //城市
    4:string AppID //客户端appID
    5:string ClientID //客户端ID
    6:i64 StartTime //开始时间(历史回看)
    7:i64 EndTime //结束时间(历史回看)
    8:i64 ChannelID //通道号
    9:double DraggingRatio //拖动比例(历史回看)
    10:i64 OffsetTime //跳转时间
    11:string ScaleType //倍速
    12:string DeviceCity //设备地域信息
}

struct PlayResponse {
    1:string ParentDeviceID
    2:i32 ParentChannlID //信道
    3:string MediaID
	4:i64 StreamType //流类型
	5:string MediaServerHost
    6:string SSRCStr
    7:i32 HttpPort
    8:string App
    9:string RtmpPlayUrl
    10:string WsFlvPlayUrl
    11: string DeviceID
    12:string DeviceCity
}


struct MergeStreamRect{
    1: i64 Screen //屏幕编号
    2: i32 x,
    3: i32 y,
    4: i32 width,
    5: i32 height,
    6: string DeviceID //设备
    7: i32 ChannlID //信道
    8: string App
    9: string MediaIP
    10: i32 HttpPort
    11: string SSRCStr
    12: string playUrl,
}

/*视频合流*/
struct MergeStreamReq{
    1: string tid,
    2: i32 width,
    3: i32 height,
    4: list<MergeStreamRect> childRect,
    /*供内部使用，thrift调用者忽略该值。将合流任务分配到哪个GPU卡*/
    5: i32 gpuCardIndex,
    6: string MergeMediaIP
    7: i32 MergeHttpPort
    8: string MergeApp
    9: string MergeSSRCStr
}

/*视频合流响应*/
struct MergeStreamResponse {
    1:list<Response>  ResponseList
    2:MergeStreamReq  StartMergeStreamResponse
}


struct MultiStreamRequest {
    1:string Tid //事务ID
    2:list<StreamRequest> StreamList
}

struct StructStreamResponse {
    1:string Tid //事务ID
    2:RespStatus Status
    3:list<StreamResponse> StreamList
}

struct  StreamResponse {
    1:Response  Response
    2:PlayResponse PlayResponse
}

struct PushStreamPort {
    1:i32 rtpPort  //双数
    2:i32 rtcpPort //单数
}

struct StreamRequest {
    1:PlayRequest PlayRequest
    2:PlayResponse PlayResponse
    3:PushStreamPort PushStreamPort //分发的推流端口
}

struct AddStreamResponse {
    1:RespStatus Status
}

struct DelStreamResponse {
    1:RespStatus Status
}


struct StreamStatResponse
{
    1:  i32 code,
    2:  string msg,
    3:  i32 readerCount,
    4:  i32 totalReaderCount,
    5:  string stream,
    6:  string originUrl,
    7:  string app,
    8:  string schema,
    9:  i64 aliveSecond,
}

struct GetMergeStreamStatusRequest
{
    1: string ssrc,
    2: string tid,
}

struct StopMergeStreamRequest
{
    1: string ssrc,
    2: string tid,
}

enum CmdStatus
{
    Unknown,
    FailedToStart,
    Running,
    Finished,
}
struct GetMergeStreamStatusResponse
{
    1: i32 code,
    2: string msg,
    3: string ssrc,
    4: CmdStatus status,
    5: string cmdStatusTip,
}

//移动设备
struct  MobilePhone{
    1:string    DeviceSerial    //设备序列号
    2:string    DeviceID        //设备ID
    3:string    SteamID         //视频流ID
    4:string    MediaID         //媒体中心ID
    5:string    Cellphone       //移动设备,手机号码
    6:string    Client          //冗余
    7:string    Application     //客户端应用
    8:i64       MobChannelNum   //可用摄像头数量
    9:string    MobIMEI         //设备IMEI(设备上网许可证)
    10:string   MobMAC          //设备MAC
    11:string   MobIP           //移动网络分配的ip地址
    12:i32      MobPort         //应用软件端口号
    13:string   MobAppURL       //访问客户端的地址
    14:string   DeviceName      //设备名称
}

//移动设备响应
struct MobileDeviceResp{
    1:string    SteamID
    2:string    DeviceID
    3:i64       ChannelID
    4:string    PushIP
    5:i32       PushPort
    6:string    AppID
    7:string    RtmpPushURL
    8:string    Msg
    9:i64       Code
    10:string   DeviceName
}

struct MobileRespList {
    1:Response Response
    2:list<MobileDeviceResp> MobileDeviceRespList
}

service MediaRouter {
    //注册移动电话录像设备
    MobileRespList RegisterMobilePhoneVideoDevice(1: MobilePhone mob)
    //登陆移动电话录像设备
    MobileRespList LoginMobilePhoneVideoDevice(1: MobilePhone mob)
    //实时视频调阅
    StreamResponse GetStream(1: PlayRequest req)
    //历史视频调阅
    StreamResponse HistoryDraggingRatioPlay (1: PlayRequest req)
    //下载历史视频
     StreamResponse DownloadHistoryVideo(1: PlayRequest req)
    //历史视频拖动
    StreamResponse HistoryOffsetPlay (1: PlayRequest req)
    //历史视频倍速播放
    StreamResponse HistoryScalePlay (1: PlayRequest req)
    // 设备管理中心添加新媒体流 并记录分配的推流端口
    AddStreamResponse AddStream(1: StreamRequest req)
    // 设备管理中心删除媒体流
    DelStreamResponse DelStream(1: StreamRequest req)
    // 视频合流调阅
    MergeStreamResponse MergeStream(1: MergeStreamReq req)
    /**查询合并视频流命令的运行状态*/
    GetMergeStreamStatusResponse getMergeStreamStatus(1: GetMergeStreamStatusRequest request),
    //视频停止合流
    /**结束合并视频流*/
    Response stopMergeStream(1: StopMergeStreamRequest request),
    // 结构化调阅
    StructStreamResponse StructStream(1: MultiStreamRequest req)
   //媒体中心配置管理
   respMedia  MediaCenterConfig(1:Method method 2: reqMedia req)
    //媒体流数据
   respMediaStream  MediaStream (1:Method method 2:reqMediaStream req)
   //媒体中心 上报视频流的观看人数
    Response   StreamStatus(1:list<StreamStatResponse>  StreamStats)
}